(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['exports', './Deflate'], factory);
    } else if (typeof module === 'object' && module.exports) {
        module.exports = factory(exports);
    } else {
        root.InflateZlib = factory(root.Deflate || (root.Deflate = {}));
    }
}(typeof self !== 'undefined' ? self : this, function (deflate_1) {
    var InflateZlib = function(streamOrWindowBits, windowBits) {
        if (typeof streamOrWindowBits === 'number') {
            this.windowBits = streamOrWindowBits;
        }
        else {
            this.stream = streamOrWindowBits;
            this.windowBits = windowBits;
        }
    }
    InflateZlib.prototype = {}

    /**
     * Inflates the Kaitai stream.
     * @param data The data to inflate. If there is no data and a stream was provided in the constructor, the stream is used instead.
     * @returns The inflated data.
     */
    InflateZlib.prototype.decode = function(data) {
        var _a;
        let windowBits = (_a = this.windowBits) !== null && _a !== void 0 ? _a : 15;
        if (windowBits < 0)
            windowBits = -windowBits;
        while (windowBits > 15)
            windowBits = windowBits - 16;
        if (this.stream)
            return (0, deflate_1.decodeStream)(this.stream, windowBits);
        else if (data.length)
            return (0, deflate_1.decodeBytes)(data, windowBits);
        else
            return new Uint8Array(0);
    }

    return InflateZlib;
}));
